﻿using Application.MainModule.RateManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.Rates;
using Domain.MainModule.Entities;
using System.Collections.Generic;
using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for RateManagementServiceTest and is intended
    ///to contain all RateManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RateManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddRate
        ///</summary>
        [TestMethod()]
        public void AddRate_Invoke_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();
            Guid rateId = Guid.NewGuid();
            Rate rate = new Rate()
            {
                RateId = rateId,                
            };

            //Act
            target.AddRate(rate);
            Rate result = target.FindRateById(rateId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(rateId, result.RateId); 
        }

        /// <summary>
        ///A test for ChangeRate
        ///</summary>
        [TestMethod()]
        public void ChangeRate_Invoke_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();
            Guid rateId = Guid.Parse("98765432-1234-AABB-AAFF-AAAACCBBBBBB");
 
            //Act
            Rate rate = target.FindRateById(rateId);
            rate.UpdateDate = new DateTime(2010, 12, 25);
            target.ChangeRate(rate);
            Rate result = target.FindRateById(rateId);

            //Assert
            Assert.IsNotNull(result);
            Assert.AreNotEqual(new DateTime(1980, 5, 10), result.UpdateDate);
        }

		/// <summary>
        ///A test for FindRateById
        ///</summary>
        [TestMethod()]
        public void FindRateById_Invoke_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();
            Guid rateId = Guid.Parse("98765432-10FD-AABB-AAFF-AAAACCBBBBBB");

            //Act 
            Rate rate = target.FindRateById(rateId);

            //Assert
            Assert.IsNotNull(rate);
            Assert.AreEqual(rateId, rate.RateId);
        }
		
        /// <summary>
        ///A test for FindRateByCountryId
        ///</summary>
        [TestMethod()]
        public void FindRateByCountryId_Invoke_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();
            Guid countryId = Guid.Parse("98765432-1234-2222-AAFF-AAAACCBBBBBB");
            List<Rate> actual;

            //Act
            actual = target.FindRateByCountryId(countryId);

            //Assert
            Assert.IsNotNull(actual);
            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual(countryId, actual[0].CountryId);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveRate_Invoke_NullItemThrowNewArgumentNullException_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();

            //Act
            target.RemoveRate(null);
        }

        /// <summary>
        ///A test for RemoveRate
        ///</summary>
        [TestMethod()]
        public void RemoveRate_Invoke_Test()
        {
            //Arrange
            IRateManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<IRateManagementService>();
            Rate rate = null;

            //Act
            rate = target.FindRateById(Guid.Parse("98765432-1234-AABB-AAFF-AAAACCBBBBBB"));
            target.RemoveRate(rate);

            //Assert
            Rate result = target.FindRateById(Guid.Parse("98765432-1234-AABB-AAFF-AAAACCBBBBBB"));
            Assert.IsNull(result);
            rate = new Rate()
                    {
                        RateId = Guid.Parse("98765432-1234-AABB-AAFF-AAAACCBBBBBB"),
                        UpdateDate = new DateTime(1980, 5, 10),
                        CountryId = Guid.Parse("98765432-1234-1111-AAFF-AAAACCBBBBBB")
                    };
            target.AddRate(rate);
        }
    }
}
